//
//  EDSOverlayView.m
//  DrivieSchoolStudents
//
//  Created by TangBin on 2019/5/24.
//  Copyright © 2019 班文政. All rights reserved.
//

#import "EDSOverlayView.h"

@interface EDSOverlayView ()

@property (nonatomic, strong) UIImageView *playImageView;

@property (nonatomic, assign) BOOL isTapPlay; ///< 是否点击播放

@property (nonatomic, strong) UIButton *btnClose; // 返回按钮

@property (nonatomic, strong) UIView *navView;

- (void)initWithSubView;

- (void)initWithNavView;

- (void)initWithPlayImageView;

@end

@implementation EDSOverlayView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initWithSubView];
    }
    return self;
}

- (void)initWithSubView
{
//    self.backgroundColor = [UIColor redColor];
    
    [self initWithNavView];
    
    [self initWithBtnClose];
    [self initWithPlayImageView];
    self.isTapPlay = NO;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPlayOrPause:)];
    [self addGestureRecognizer:tap];
}

- (void)initWithNavView
{
    if (!_navView)
    {
        CGRect frame = CGRectMake(0, 0, kScreenWidth, NAVBAR_HEIGHT_STATUS);
        _navView = [[UIView alloc] initWithFrame:frame];
        _navView.backgroundColor = [UIColor redColor];
        _navView.userInteractionEnabled = NO;
//        [self addSubview:_navView];
    }
}

- (void)initWithBtnClose
{
    if (!_btnClose)
    {
        //        int height = (kScreenHeight >= 812?33+24:33);
//        kNavigationH 88 64
        float bottom = (44 - 40) * 0.5;
        CGRect frame = CGRectMake(0, NAVBAR_HEIGHT_STATUS - 44 +bottom, 40, 40);
        _btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnClose.frame = frame;
        
        [_btnClose setImage:[UIImage imageNamed:@"community_left"] forState:UIControlStateNormal];
        [_btnClose addTarget:self action:@selector(clickedClose:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_btnClose];
    }
}

- (void)initWithPlayImageView
{
    if (!_playImageView)
    {
        CGRect frame = CGRectMake(0, 0, 69, 69);
        _playImageView = [[UIImageView alloc] initWithFrame:frame];
        _playImageView.image = [UIImage imageNamed:@"com_play_big_ic"];
        _playImageView.center = CGPointMake(self.width * 0.5, self.height * 0.5);
        [self addSubview:_playImageView];
    }
}

/**
 点击让旋转轮小时后，旋转轮 停止后调用
 */
- (void)loadStop
{
    [self tapPlayOrPause:nil];
}


/**
 点击，播放或者暂停

 @param tap tap description
 */
- (void)tapPlayOrPause:(UITapGestureRecognizer *)tap
{
    self.isTapPlay = !self.isTapPlay;
    if (self.isTapPlay)
    {// 点击播放
        self.playImageView.hidden = YES;
        if (self.delegate && [self.delegate respondsToSelector:@selector(play)])
        {
            [self.delegate play];
        }
    }
    else
    {// 点击暂停
        self.playImageView.hidden = NO;
        if (self.delegate && [self.delegate respondsToSelector:@selector(pause)])
        {
            [self.delegate pause];
        }
    }
}

- (void)clickedClose:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(back)])
    {
        [self.delegate back];
    }
}

/**
 播放完成
 */
- (void)playbackComplete
{
    NSLog(@"eeeee");
}

- (void)bgPause
{
    self.playImageView.hidden = NO;
    self.isTapPlay = NO;
}

@end

























